package model;

import helperclasses.DbUtil;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import javax.sql.DataSource;

public class ViewSalesClass {

	
	public ViewSalesClass(){
		
	}

	private Connection getConnection() throws SQLException {
		DataSource ds = DbUtil.getInstance().getDataSource();
		Connection conn = ds.getConnection();
		return conn;
	}
	
	public List<String> ViewAllSales() throws SQLException{
		List<String> vanzari = new ArrayList<String>();				
		Connection conn = getConnection();
		Statement st = conn.createStatement();
		String sql;

		sql = "SELECT data_nota FROM sales GROUP BY data_nota ORDER BY data_nota DESC";

		try {
			ResultSet result = st.executeQuery(sql);
			while (result.next()) {
				vanzari.add(result.getString("data_nota"));
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			st.close();
			conn.close();
		}	
		return vanzari;
	}
}